package com.wz.file;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.*;

public class FileMaker {
	private static Logger log = LoggerFactory.getLogger(FileMaker.class);

	public static void writeFile(String filePath, String filedir, String content){
		File newfile = new File(filedir);
		if (!newfile.exists()){
			newfile.mkdir();
		}
		if (!exists(filePath)){
			createNewFile(filePath);
		}
		write(filePath, content);
	}

	public static boolean createNewFile(String filePath){
		File file = new File(filePath);
        try{
        	return file.createNewFile();
        }catch(Exception e){
                 e.printStackTrace();
                 return false;
        }
	}

	public static boolean exists(String filePath){
		File file = new File(filePath);
		return file.exists();
	}

	public static List<String> readFile(String filePath){
		FileInputStream fis = null;
		List<String> arrayList = new ArrayList<String>();
		try{
			fis = new FileInputStream(filePath);
			BufferedReader dr=new BufferedReader(new InputStreamReader(fis));
			String line =  dr.readLine();
			while(line!=null){
				arrayList.add(line);
				line = dr.readLine();
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
				fis.close();
			}catch(Exception e){}
		}
		return arrayList;
	}
	
	public static void write(String path, String content){
		FileOutputStream fos = null;
		try{
			File newfile = new File(path);
			fos = new FileOutputStream(newfile,true);
			byte[] b1 = content.getBytes();
			byte[] b2 = "\r\n".getBytes();
			fos.write(b1);
			fos.write(b2);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try{
				fos.close();
			}catch(Exception e){}
		}
	}

	public static String getInsertSQL(String[] str, int operid, String operName){
		StringBuilder insert = new StringBuilder("INSERT INTO `channelManager` VALUES ('006001',");
//		log.info(str[0] + ":" + str[1]+ ":" + str[2]);
		insert.append("").append(str[2].trim()).append(",'100', '1000000792', '").append(str[0].trim()).append("', '*',").append(str[1].trim()).append(", '1', ").append(operid).append(",'1', '").append(operName).append("', '007ka792接口', '3');");
		return insert.toString();
	}
	
	public static void main(String[] args) {
		List<String> file = readFile("C:\\Users\\Lenovo\\Desktop\\bankcard.txt");
		int j = 10000;
		Set<String> bankName = new HashSet();
		for (String s : file) {
			String[] bankinfo = s.split(",");
			String s3 = "";
			for (int i = 0; i < 4 ; i ++){
				if (i == 1){
					if (bankinfo[i].trim().contains("(")){
						bankName.add(bankinfo[i].trim().split("\\(")[0].trim());
					} else bankName.add(bankinfo[i].trim());
				}
				s3 = s3 + "'" + bankinfo[i] + "',";
			}
			//String s2 = "(" + s3.substring(0, s3.length() - 1) + "),";
			//log.info(s2);
		}
		String s4 = "";
		for (String bn : bankName) {
			if (bn.equals("龙江银行股份有限公司")){
				System.out.println("11");
			}

			log.info("('" + j +  "','" + bn + "','" + bn + "'),");
			j++;
		}
	}

}